﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.Json;
using System.ComponentModel;

namespace ClockLib
{
    public class ClockSettings
    {
        [Description("报时时刻")]
        public int[] ReportMinutes { get; set; } = new int[] {
        0,30};
        [Description("静默时段")]
        public int[] SilentHours { get; set; } = new int[] { 0, 1, 2, 3, 4, 5, 6,23 };
        [Description("启用整点钟声")]
        public bool EnableBellRing { get; set; } = true;

        [Description("钟声播放次数")]
        public int BellRepeatTime { get; set; } = 1;

        [Description("启用语音报时")]
        public bool EnableTimeReport { get; set; } = true;

        public int CheckPeriod { get; set; } = 30;

        //public bool Silent { get; set; } = false;

        //[Description("语音报时音频文件夹地址")]
        //public string ReportAudioFolderPath { get; set; } = null!;
        public string ReportTemplate { get; set; } = "现在是{hour}点{minute}分";
        public static ClockSettings Load(string file_path = "clock_settings.json")
        {
            if (File.Exists(file_path) == false)
            {
                return new ClockSettings();
            }
            var text = File.ReadAllText(file_path);
            return JsonSerializer.Deserialize<ClockSettings>(text) ?? new ClockSettings();
        }
        public void Save(string file_path = "clock_settings.json")
        {
            var json = JsonSerializer.Serialize<ClockSettings>(this, options: new JsonSerializerOptions
            {
                WriteIndented = true,
                ReadCommentHandling = JsonCommentHandling.Skip,
            });
            File.WriteAllText(file_path, json);

        }
    }
}
